package com.egg.ylt;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.text.style.ClickableSpan;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.egg.ylt.Utils.Constants;
import com.egg.ylt.Utils.SocketCallBack;
import com.egg.ylt.Utils.SocketUtil;
import com.egg.ylt.Utils.StringSpanUtils;
import com.egg.ylt.pojo.RealtimeDataEntity;
import com.egg.ylt.widget.RingChartView;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    TextView textView;
    private static final String TAG = "MainActivity";
    RingChartView ringChartView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ringChartView = findViewById(R.id.ring_chard);
        ringChartView.setCurrentData(13);
//        textView = findViewById(R.id.main_test);
        textView.setText(StringSpanUtils.init()
                .addForegroundColorHighLightWithKey(R.color.blue_4285f4, "woasdgggqwe是sei在敲打我窗，是谁，在，是谁。", "G")
                .addRelativeScale(2.0f, "woasdgggqwe是sei在敲打我窗，是谁，在，是谁。")
                .addForegroundColorHighLight(getResources().getColor(R.color.color_FF2020), "我对你爱爱爱爱不完")
                .addRelativeScaleWithKey(0.8f, "111112222233333", "2")
                .setDeleteLineWithKeyAndPosition("是谁", 1)
                .setClickableWithPosition(1, new ClickableSpan() {
                    @Override
                    public void onClick(@NonNull View widget) {

                    }
                }, textView)
                .build());
        SocketUtil<RealtimeDataEntity> socketUtil = new SocketUtil<>("192.168.98.186", 14400,
                new SocketCallBack<RealtimeDataEntity>() {
            @Override
            public void onConnected() {
                Log.e(TAG, "onConnected: ");
            }

            @Override
            public void onDisconnected() {
                Log.e(TAG, "onDisconnected: ");
            }

            @Override
            public void onReconnected() {
                Log.e(TAG, "onReconnected: ");
            }

            @Override
            public void onSend() {

            }

            @Override
            public void onReceived(RealtimeDataEntity msg) {
                Log.e(TAG, "onReceived: " + msg);
            }

            @Override
            public void onError(String msg) {
                Log.e(TAG, "onError: " + msg);
            }
        });
        Map<String, String> map = new HashMap<>();
        map.put("companyId", Constants.COMPANYID);
        map.put("shopId", "1");
        String str = JSON.toJSONString(map);
        Log.e(TAG, "onCreate: " + str);
        socketUtil.setDefaultMsg(str);
//        socketUtil.create();
    }
}
